*******************************************************************************************
***
*** Do file: The Foreign Policy Rhetoric of Populism: Chávez, Oil and Anti-Imperialism
*** Sagarzazu, Inaki and Cameron Thies
*** May 25, 2018
***
*******************************************************************************************


use "finalData/data_figure1.dta", clear


*** FIGURE 1

tsset date
tsline smt_imper || tsline smt_total, /*
*/ yaxis(2) legend(label(1 "Imperialism") label(2  "Total") pos(6) col(2)) /*
*/ scheme(lean2) xtitle("Date") ytitle("Number of Sentences") /*
*/ ytitle("Number of Sentences", axis(2)) ylabel(0(500)2000,axis(2))


use "dataset_final.dta", clear

keep yearqtr oil_qtr gdp_qtr evalgestion_negativa pr_imperialism  events term quartersInOffice W 

*** FIGURE 2
gen pct_imperialism=100* pr_imperialism
tsline oil if yearqtr>yq(1999,2) & yearqtr<yq(2012,2) || /*
*/ tsline pct_imperialism if yearqtr>yq(1999,2) & yearqtr<yq(2012,2), yaxis(2) /*
*/ ytitle("Attention to Imperialism", axis(2)) ytitle("Price of Oil") xtitle("Year-Quarter") /*
*/ legend(label(1 "Price of Oil") label(2 "Imperialism") pos(6) cols(2)) scheme(lean2)



dfuller pr_im
* reject null of random walk  -->Stationary

dfuller oil_qtr 
* cant reject null of random walk 
gen d_oil = oil_qtr - l.oil_qtr
dfuller d_oil
* reject null of random walk --> Stationary

dfuller evalgestion_negativa
* cant reject null of random walk 
gen d_eval = evalgestion_negativa - l.evalgestion_negativa
dfuller d_eval
* reject null of random walk --> Stationary


dfuller gdp_qtr 
* cant reject null of random walk 
gen d_gdp = gdp_qtr - l.gdp_qtr
dfuller d_gdp
* reject null of random walk --> Stationary


*** TABLE 1

quietly: reg pr_imperialism d_oil d_eval d_gdp events term quartersInOffice l(1/2).pr_imperialism W 
est store model1
predict resid1, resid
wntestq resid1

quietly: reg pr_imperialism d_oil d_eval d_gdp events term l(1/2).pr_imperialism W 
est store model2
predict resid2, resid
wntestq resid2

quietly: reg pr_imperialism d_oil d_eval d_gdp  events quartersInOffice  l(1/2).pr_imperialism W 
est store model3
predict resid3, resid
predict y_hat
wntestq resid3

est table model1 model2 model3, star(0.05 0.01 0.1) stats(N r2 ll)

**** FIGURE 3
quietly: margins , at(d_oil=(-50(1)50))  
marginsplot, scheme(lean2) ytitle("% Predicted attention") xtitle("Change in Price of Oil") recast(line) recastci(rarea)



